﻿using CTM.Web.Data;
using CTM.Web.Models.Input;
using CTM.Web.Repositories;
using System.Linq;

namespace CTM.Web.Services
{
    public interface ITagService : IApplicationService<Tag>
    {
        Tag GetByName(string name);
    }

    public class TagService : ApplicationService<Tag>, ITagService
    {
        private IUnitOfWork unitOfWork;
        private ITagRepository tagRepository;

        public TagService(IUnitOfWork unitOfWork, ITagRepository tagRepository)
            : base(unitOfWork, tagRepository)
        {
            this.unitOfWork = unitOfWork;
            this.tagRepository = tagRepository;
        }

        public Tag GetByName(string name)
        {
            return tagRepository.Get(x => x.Name == name).FirstOrDefault();
        }
    }
}